<?php

class Model_Default{

    /**
     * 获取对应名称和对应传值的方法
     */
    private function getCompanyName( $order ){
        $name = json_decode(file_get_contents("http://www.kuaidi100.com/autonumber/autoComNum?text={$order}"), true)['auto'];
        $result = $name[0]['comCode'];
        if (empty($result)) {
            return false;
        } else {
            return $result;
        }
    }

    /**
     * 返回快递物流信息
     * @param string $order 快递的单号
     * @return int|mixed
     */
    public function getExpressInfo($order)
    {
        $keywords = $this->getCompanyName($order);
        if (!$keywords) {
            return ReturnCode::NOT_EXISTS;
        } else {
            $result = file_get_contents("http://www.kuaidi100.com/query?type={$keywords}&postid={$order}");
            $data = json_decode($result, true);
            $data['companyCode'] = $keywords;
            return $data;
        }
    }

    public function getBarCodeInfo($ean){
        $url = "http://www.topscan.com/tiaoma/query.php";
        $data = ['ean'=>$ean];
        $result = (new PhalApi_CUrl())->post($url,$data);
        $data = json_decode($result, true);
        return $data;
    }

}